﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ListenMusic.AdminMember_ServiceReference;
using PagedList;
namespace ListenMusic.Controllers.Admin
{
    public class ManageMemberController : AdminController
    {
        //
        // GET: /ManageMember/
        //[Authorize(Roles="WebsiteAdmin")]
        private int pagesize = 20;
        public ActionResult AllMember(int? pageindex)
        {
            if (pageindex == null)
            {
                pageindex = 1;
            }
            List<MembershipUserRole> membership = _mangeMember.getAllMembershipUser().ToPagedList((pageindex ?? 1),pagesize).ToList();
            if (membership.Count < 1)
            {
                return View("~/View/Shared/_ErrorAdmin.cshtml");
            }
            else
            {
                int countMember = _mangeMember.getAllMembershipUser().Count();
                int totalMember = 0;
                if (countMember % pagesize == 0)
                {
                    totalMember = (int)countMember / pagesize;
                }
                else
                {
                    totalMember = (int)Math.Ceiling((double)(countMember) / pagesize);
                }
                ViewBag.pageindex = pageindex;
                ViewBag.countMember = countMember;
                ViewBag.totalMember = totalMember;
                ViewBag.membershipUser = membership;
                return View("ViewAllMember");
            }
        }
        //[Authorize(Roles="WebsiteAdmin")]
        public ActionResult ViewMemberIsLock(int? pageindex)
        {
            if (pageindex == null)
            {
                pageindex = 1;
            }
            List<MembershipUserRole> membership = _mangeMember.getAllMembershipUser_isLock().ToPagedList((pageindex ?? 1),pagesize).ToList();
            int countMember = _mangeMember.getAllMembershipUser_isLock().Count();
                int totalMember = 0;
                if (countMember % pagesize == 0)
                {
                    totalMember = (int)countMember / pagesize;
                }
                else
                {
                    totalMember = (int)Math.Ceiling((double)(countMember) / pagesize);
                }
                ViewBag.pageindex = pageindex;
                ViewBag.countMember = countMember;
                ViewBag.totalMember = totalMember;
                ViewBag.membershipUser = membership;
                return View();
              
         
        }
        //[Authorize(Roles="WebsiteAdmin")]
        public JsonResult LockOrUnlockAccount(Guid userId)
        {
            bool rs = _mangeMember.LockOrUnlockAccount(userId);
            return Json(rs, JsonRequestBehavior.AllowGet);
        }
    }
}
